﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace UI.Web
{
 /// <summary>
    /// AjaxAction 的摘要说明
    /// </summary>
    public class AjaxAction : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string dowhat = context.Request["dowhat"];
            if (dowhat == null) dowhat = "";
          
            if (dowhat.Equals("login"))
            {
                string delim = "  ";
                string xuehao = context.Request["xuehao"].Trim(delim.ToCharArray());
                string password = context.Request["password"].Trim(delim.ToCharArray());
               
                if (xuehao.Length < 1 && password.Length > 0)
                {
                    context.Response.Write("*请输入用户名");
                    return;
                }
                else if (password.Length < 1 && xuehao.Length > 0)
                {
                    context.Response.Write("*请输入密码");
                    return;
                }
                else if (password.Length < 1 && xuehao.Length < 1)
                {
                    context.Response.Write("*请输入用户名和密码");
                    return;
                }
               
                else if (xuehao.Length > 0 && password.Length > 0)
                {
                    Models.Team team = BLL.Find.FindTeam(xuehao, password);
                    if (team != null)
                    {
                        
                      
                        HttpContext.Current.Response.Write("success");
                     
                    }
                    else
                    {
                        context.Response.Write("*用户名和密码不匹配");
                    }
                    context.Response.End();
                    return;
                }
            }
            if (dowhat == "getpassword")
            {
                string delim = "  ";
                string chepai = context.Request["chepai"].Trim(delim.ToCharArray());
                Models.ofo ofo = BLL.Find.Findofo("chepai",chepai);
                if (ofo != null)
                {


                    HttpContext.Current.Response.Write(ofo.password);

                }
                else { HttpContext.Current.Response.Write("failed"); }

            }
            if (dowhat == "addche")
            {
                string delim = "  ";
                string chepai = context.Request["chepai"].Trim(delim.ToCharArray());
                 string author = context.Request["author"].Trim(delim.ToCharArray());
                string password = context.Request["password"].Trim(delim.ToCharArray());
                Models.ofo ofo = BLL.Find.Findofo("chepai",chepai);
                if (ofo != null)
                {


                    HttpContext.Current.Response.Write("车牌号码已存在，不用重复添加");
                    return;

                }
                else { 
                    BLL.Create.Createofo(chepai,password,author,"");
                    HttpContext.Current.Response.Write("success");
                }

            }
           
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
